#!/bin/bash

BASE_CONF=docker/base.conf
COMPOSE_YAML=docker/docker-compose.yml

composeService(){
    op=$1
    service=$2
    num=$3
    num=${num:=1}
    case $op in
    'start')
        docker-compose --env-file ${BASE_CONF} -f ${COMPOSE_YAML} start ${service}
        ;;
    'restart')
        docker-compose --env-file ${BASE_CONF} -f ${COMPOSE_YAML} restart ${service}
        ;;
    'up')
        if [ $num -eq '1' ]; then
            docker-compose --env-file ${BASE_CONF} -f ${COMPOSE_YAML} up -d ${service}
        else
            docker-compose --env-file ${BASE_CONF} -f ${COMPOSE_YAML} up -d ${service} --scale ${service}=${num}
        fi
        ;;
    'stop')
        docker-compose --env-file ${BASE_CONF} -f ${COMPOSE_YAML} stop ${service}
        ;;
    'down')
        docker-compose --env-file ${BASE_CONF} -f ${COMPOSE_YAML} down ${service}
        ;;
    esac
}

composeService $@
